package com.xxgc.ssm.resolver;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;

//自定义登录异常处理类
public class LoginExceptionResolver implements HandlerExceptionResolver {

    //参数 Exception
    //返回结果  ModelAndView
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        ModelAndView modelAndView = new ModelAndView();
        if(e instanceof FileNotFoundException){
            modelAndView.addObject("code","FZ-0012-B");
            modelAndView.addObject("msg","文件异常");
            modelAndView.addObject("version","V3.4.2");
            httpServletResponse.setStatus(500);
            //文件错误
            modelAndView.setViewName("error/file_error.jsp");
            //返回页面之前记录错误日志到数据库
        }else{
            modelAndView.setViewName("error/error.jsp");
        }
        return modelAndView;
    }
}